package com.example.classtest.controller;

import com.example.classtest.model.GoodsInfo;
import com.example.classtest.service.GoodsService;
import com.example.classtest.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @RequestMapping("/add")
    public ResultData add(GoodsInfo goods){
        List<GoodsInfo> goodsInfos = goodsService.add(goods);
        return ResultData.ok(goodsInfos,"添加成功");
    }

    @RequestMapping("/delete")
    public ResultData delete(GoodsInfo goods){
        List<GoodsInfo> goodsInfos = goodsService.delete(goods);
        return ResultData.ok(goodsInfos,"删除成功");
    }

    @RequestMapping("/subtotal")
    public ResultData subTotal(){
        double result = goodsService.subTotal();
        return ResultData.ok(result,"");
    }

    @RequestMapping("/total")
    public ResultData total(){
        double result = goodsService.total();
        return ResultData.ok(result,"");
    }
}
